<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>首页</title>
		<link rel="stylesheet" type="text/css" href="js/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="themes/bootstrap/easyui.css">
		<link rel="stylesheet" type="text/css" href="themes/icon.css">
		<link rel="stylesheet" type="text/css" href="themes/color.css">
		<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
	</head>
		<script type="text/javascript">
			$(function(){
				$("#register").hide();
				$("#loginWindow").show();
				$('#registerName').validatebox({
				    required: true,    
				    validType:['string','length[6,15]'],
				    missingMessage : '请输入注册名',
				});
				$('#registerPassword').validatebox({    
				    required: true,    
				    validType:['string','length[7,15]'],
				    missingMessage : '请输入密码',
				});
				$('#registerPasswordAgain').validatebox({    
				    required: true,    
				    validType:['string','length[7,15]'],
				    missingMessage : '请再次输入密码',
				});
				$('#loginName').textbox({    
				    iconCls:'icon-man', 
				    iconAlign:'left',
				    prompt : '请输入用户名',
				});
				$('#loginPassword').textbox({    
				    iconCls:'icon-man', 
				    iconAlign:'left',
				    prompt : '请输入密码',
				})
				$('#registerWindow').window({    
				    width:400,    
				    height:300,    
				    modal:true   
				});
				$($("input[type='text']").get(1)).blur(function(){
					var password =$($("input[type='text']").get(1)).val();
				})
				$("#regButton").click(function(){
					$("#register").show();
					$("#loginWindow").hide();
				});
				$("#registerButton").click(function(){
					$.ajax({
						url : 'register',
						data : {
							regName : $("input[name='uname']").val(),
							regPassword : $("input[name='upswd']").val(),
							regPasswordAgain : $("#registerPasswordAgain").val()
						},
						dataType : 'json',
						type : 'post',
						success : function(r){
							 if(r.code === 1){
									$.messager.confirm('确认','注册名或密码或再次输入密码未输入,注册失败!',function(r){
										$("input[name='uname']").textbox('clear');
										$("input[name='upswd']").textbox('clear');
										$("#registerPasswordAgain").textbox('clear');
									}); 
							} else if(r.code === 2) {
								$.messager.confirm('确认','两次输入的密码不一致,注册失败!',function(r){
									$("input[name='uname']").textbox('clear');
									$("input[name='upswd']").textbox('clear');
									$("#registerPasswordAgain").textbox('clear');
								});
							} else if(r.code === 3 ) {
								$("#loginWindow").show();
								$.messager.confirm('确认','注册成功!',function(r){
									$("input[name='uname']").textbox('clear');
									$("input[name='upswd']").textbox('clear');
									$("#registerPasswordAgain").textbox('clear');
								});
								$("#register").hide();
							}
						}
					});
				});
				$("#loginButton").click(function(){
					$.ajax({
						url : 'login',
						data : {
							uname : $("#loginName").val(),
							upswd : $("#loginPassword").val()
						},
						dataType : 'json',
						type : 'post',
						success : function(r){
							if(r.code == 1) {
								location.href = 'main.jsp';
							} else {
								$.messager.confirm('确认','用户名或密码错误,登录失败!',function(r){
								}); 
								$("#loginPassword").textbox('clear');
							}
						}
					});
				})
			})
		</script>
	<body>
		<div id="registerWindow" class="row form-group">
			<div style="margin-top: 50px;" align="center" id="register">
				注册名<input name="uname" type="text" style="display: block;"/>
				密码<input name="upswd" type="text" style="display: block;"/>
				再次输入密码<input id="registerPasswordAgain" type="text" style="display: block;"/>
				<button type="button" id="registerButton" class="btn btn-default">确认注册</button>
			</div>
			<div id='loginWindow' style="margin-top: 50px;" align="center" id="login">
				<input id="loginName" type="text" style="width: 150px; display: block;"><br/>
				<input id="loginPassword" type="password" style="width:150px; display: block;"><br/>
				<button type="button" id="loginButton" class="btn btn-default">登录</button>
				<button type="button" id="regButton" class="btn btn-default">注册</button>
			</div>
		</div>
	</body>
</html>